package com.oamicnet.serviceone.server.controller;


import com.oamicnet.serviceone.api.teacher.vo.TeacherVO;
import com.oamicnet.serviceone.server.service.TeacherService;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/teacher")
@RefreshScope
public class TeacherController {

    @Value("${custom.key}")
    private String customKey;

    @Autowired
    public TeacherService teacherService;

    @GetMapping("/{id}")
    public TeacherVO getTeacherById(@PathVariable("id") Long id, HttpServletRequest request) {
        System.out.println("customKey=" + customKey);
        System.out.println("X-Request-Red=" + request.getHeader("X-Request-Red"));
        System.out.println("User-Type=" + request.getHeader("User-Type"));
        return teacherService.get(id);
    }

    @GetMapping
    public List<TeacherVO> getTeachers() {
        return teacherService.findAll();
    }

    @PostMapping
    public void saveTeacher(@RequestBody TeacherVO teacher) {
        teacherService.save(teacher);
    }

    @PutMapping
    public void updateTeacher(@RequestBody TeacherVO teacher) {
        teacherService.update(teacher);
    }

    @DeleteMapping("/{id}")
    public void deleteTeacher(@PathVariable("id") Long id) {
        teacherService.delete(id);
    }
}
